/**
 * 题目：https://leetcode-cn.com/problems/reverse-integer/
 * 题解：https://shentuzhigang.blog.csdn.net/article/details/114296861
 */
class Solution {
    public int reverse(int x) {
        String str = String.valueOf(x);
        String s = "";
        if (str.charAt(0) == '-') {
            s = "-";
            str = str.substring(1);
        }
        Long res = Long.valueOf(s + new StringBuilder(str).reverse().toString());
        if (res > Integer.MAX_VALUE || res < Integer.MIN_VALUE) {
            return 0;
        } else {
            return res.intValue();
        }
    }
}